<?php
declare (strict_types = 1);

namespace app\admin\validate;

use app\admin\exception\ParameterException;
use think\facade\Request;
use think\Validate;

class BaseValidate extends Validate
{
    const Save = 'save';
    const Update = 'update';

    public function goCheck($scene = 'save')
    {
        // 获取http传入的参数
        // 对这些参数校验
        $params = Request::param();
        $result = $this->batch(true)->scene($scene)->check($params);
        if (!$result) {
            $error = is_array($this->error) ? implode(
                ';', $this->error) : $this->error;
            throw new ParameterException([
                'msg' => $error,
                'code' => 400
            ]);
        } else{
            return true;
        }
    }
    protected function isPositiveInteger($value)
    {
        if (is_numeric($value) && is_int(($value + 0)) && ($value + 0) > 0){
            return true;
        }else{
            return false;
        }
    }
    protected function isNotEmpty($value)
    {
        if (empty($value))
        {
            return false;
        }else{
            return true;
        }
    }
}
